package com.huaxin.hxcloud.fragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huaxin.common.Entity.HxWarningBean;
import com.huaxin.common.message.util.DateUtils;
import com.huaxin.hxcloud.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hebing on 2017/8/25.
 * 警告adapter
 */

public class HxWarningListAdapter extends RecyclerView.Adapter<HxWarningListAdapter.ViewHolder> {

    private       Context                             mContext;
    private final LayoutInflater                      mInflater;
    private       List<HxWarningBean.WarningListBean> mWarningListBeen;

    public HxWarningListAdapter(Context context, List<HxWarningBean.WarningListBean> warningListBeen) {
        this.mContext = context;
        this.mWarningListBeen = warningListBeen;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = mInflater.inflate(R.layout.item_warning_warning, parent, false);
        return new ViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HxWarningBean.WarningListBean listBean = mWarningListBeen.get(position);
        holder.mTvTitle.setText(listBean.getDes());
        holder.mTvStationName.setText(listBean.getStationName());
        holder.mTvDate.setText(DateUtils.getWarnTime(listBean.getCreateDate()));
    }

    @Override
    public int getItemCount() {
        return mWarningListBeen == null ? 0 : mWarningListBeen.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title)
        TextView mTvTitle;
        @BindView(R.id.tv_station_name)
        TextView mTvStationName;
        @BindView(R.id.tv_date)
        TextView mTvDate;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
